//package cn.rabbitmq.springbootrabbitmq.highPushConfirm.controller;
//
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.amqp.rabbit.connection.CorrelationData;
//import org.springframework.amqp.rabbit.core.RabbitTemplate;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.PathVariable;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import javax.annotation.PostConstruct;
//
//@RestController
//@RequestMapping("/confirms")
//@Slf4j
//public class Producer implements
//        RabbitTemplate.ConfirmCallback {
//    public static final String CONFIRM_EXCHANGE_NAME = "confirm.exchange";
//    @Autowired
//    private RabbitTemplate rabbitTemplate;
//
//
//    @PostConstruct
//    public void init() {
//        rabbitTemplate.setConfirmCallback(this);
//    }
//
//    //-------------------------------发送两个消息 -------------------------------
//    @GetMapping("sendMessage/{message}")
//    public void sendMessage(@PathVariable String message) {
//        //指定消息 id 为 1
//        CorrelationData correlationData1 = new CorrelationData("1");
//        String routingKey = "key1";
//        rabbitTemplate.convertAndSend(CONFIRM_EXCHANGE_NAME, routingKey, message + routingKey, correlationData1);
//
//        CorrelationData correlationData2 = new CorrelationData("2");
//        routingKey = "key2";
//
//        rabbitTemplate.convertAndSend(CONFIRM_EXCHANGE_NAME, routingKey, message + routingKey, correlationData2);
//        log.info("发送消息内容:{}", message);
//    }
//
//    /**
//     * 交换机不管是否收到消息的一个回调方法
//     * CorrelationData
//     * 消息相关数据
//     * ack
//     * 交换机是否收到消息
//     */
//    @Override
//    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
//        String id = correlationData != null ? correlationData.getId() : "";
//        if (ack) {
//            log.info("交换机已经收到 id 为:{}的消息", id);
//        } else {
//            log.info("交换机还未收到 id 为:{}消息,由于原因:{}", id, cause);
//        }
//    }
//
//}
